<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>AUI快速完成布局</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />


</head>

<body>
    <div style="padding:20px;">

        <div id="list">

        </div>
    </div>


</body>
<script type="text/template" id="template">
    <div class="aui-row" style="border-bottom:1px solid #ccc" onclick="fnOpenSheet()" data-id="">
        <div class="aui-col-xs-2">
            <div style="line-height:40px;color:green;overflow:hidden" id="real-name">
                {{=it.real_name}}
            </div>
        </div>
        <div class="aui-col-xs-8">

            <div style="line-height:40px;">
                {{=it.alipay_account}}
            </div>
        </div>
        <div class="aui-col-xs-2">

            <div style="line-height:40px;">
                <botton style="color:red">修改</botton>
            </div>
        </div>

    </div>

</script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="./conf/config.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript">
    apiready = function() {
        //fnGetDataCommon(template_,url_,method_,data_,userinfo_=1)
    fnGetDataCommon("ListAlipay","index.php?m=api&c=appnew&a=cash_account_info","post");

        //fnGetUserInfo(); //获取用户信息分配到模板
      initRefreshCommon('fnGetDataCommon("ListAlipay","index.php?m=api&c=appnew&a=cash_account_info","post")');

        //fnGetListAlipayBind(api.pageParam.realName);
        //initRefresh();
    };
function ListAlipayRes(ret){
  var data = {
          "real_name": api.pageParam.realName,
          "alipay_account": ret.data.alipay_account
      }
      //alert(data);
      //把数据分配到前端模板
  fnUpdataListAlipayBind(data);
}



    function fnGetListAlipayBind(realName) {

        var userInfo = $api.getStorage("userInfo");
        var userid = userInfo.userid;
        var random = userInfo.random;

        api.ajax({
            url: SITE_URL + 'index.php?m=api&c=appnew&a=cash_account_info',
            method: 'POST',
            data: {
                values: {
                    "userid": userid,
                    "random": random,
                }
            }
        }, function(ret, err) {
            //alert(JSON.stringify(ret));
            api.refreshHeaderLoadDone(); //下拉刷新隐藏
            if (ret.status == 1) {
                var data = {
                        "real_name": realName,
                        "alipay_account": ret.data.alipay_account
                    }
                    //alert(data);
                    //把数据分配到前端模板
                fnUpdataListAlipayBind(data);

            } else if (ret.status == 5) {

                alert("未绑定支付宝，请先绑定！");
                api.closeWin();
            } else {
                alert(ret.msg);
            }

        });
    };
    //把数据分配到模板上面

    function fnUpdataListAlipayBind(ret) {

        // 1. 编译模板函数
        var interText = doT.template($api.byId('template').innerHTML); //找到模板多次使用

        $("#list").html(interText(ret));

    }

    function fnOpenSheet() {
        api.actionSheet({
            title: '操作',

            buttons: ['修改']
        }, function(ret, err) {
            var index = ret.buttonIndex;
            fnEditAlipayBind();
        });

    }

    function fnEditAlipayBind() {
        api.openWin({
            name: 'edit_alipay_',
            url: './page1.html',
            pageParam: {
                name: 'test'
            }
        });

    }

    function fnEditAlipayBind(orderId) {
        var dialogBox = api.require('dialogBox');
        dialogBox.input({
            keyboardType: 'default',
            texts: {
                title: '修改支付宝账号为：',
                placeholder: '请输入修改的支付宝账号',
                leftBtnTitle: '取消',
                rightBtnTitle: '确定'
            },
            styles: {
                bg: '#fff',
                corner: 2,
                w: 300,
                h: 180,
                title: {
                    h: 40,
                    marginT: 20,
                    alignment: 'center',
                    size: 16,
                    color: '#000',

                },
                input: {
                    h: 60,
                    marginLeft: 10,
                    marginRight: 10,
                    textSize: 14,
                    textColor: '#000',
                    borderWidth: 1
                },
                dividingLine: {
                    width: 0.5,
                    color: '#696969'
                },
                left: {
                    bg: 'rgba(0,0,0,0)',
                    color: '#007FFF',
                    size: 12,
                    h: 40
                },
                right: {
                    bg: 'rgba(0,0,0,0)',
                    color: '#007FFF',
                    size: 12,
                    h: 40
                }
            }
        }, function(ret) {
            // var index = ret.buttonIndex;
            // var text = ret.text;
            // if (index == 1) {
            //     //alert(text);
            //     fnSubmitOrderNumber(text, orderId);
            // }
            // api.alert({
            //     msg: JSON.stringify(ret)
            // });
            if (ret.eventType == 'right') {


                fnSubmitOrderNumber(ret.text, orderId);
                //  alert(ret.text);

            }
            var dialogBox = api.require('dialogBox');
            dialogBox.close({
                dialogName: 'input'
            });

        });
        return false;
        /*api.prompt({
            title: '修改支付宝账号为：',
            buttons: ['确定', '取消']
        }, function(ret, err) {
            var index = ret.buttonIndex;
            var text = ret.text;
            if (index == 1) {
                //alert(text);
                fnSubmitOrderNumber(text, orderId);
            }
        });*/
    }

    function fnSubmitOrderNumber(text, orderId) {
        var userInfo = $api.getStorage('userInfo');
        var random = userInfo.random;
        var userid = userInfo.userid;
        //alert(text);
        //alert(random);
        api.ajax({
            url: SITE_URL + 'index.php?m=api&c=appnew&a=bind_alipay_info1',
            method: 'POST',
            data: {
                values: {
                    "userid": userid,
                    "random": random,
                    "account": text
                }
            }
        }, function(ret, err) {
            if (ret.status == 1) {
                fnGetDataCommon("ListAlipay","index.php?m=api&c=appnew&a=cash_account_info","post");
            } else {
                alert(ret.msg);
            }
            //alert(ret.msg);

        });



    }
</script>

</html>
